package qj.tool.jna.support;

import java.awt.event.KeyEvent;

import qj.tool.build.BuildUtil;
import qj.tool.jna.KeyboardHandler;
import qj.ui.DesktopUI4;
import qj.util.Clipboard;
import qj.util.ThreadUtil;
import qj.util.funct.Fs;
import qj.util.funct.P0;

public class QuickMac {
	public static void main(String[] args) {
//		System.out.println(KeyboardHandler.LSHIFT);
		KeyboardHandler.mapReleased('R', new P0() {public void e() {
			if (
					isCtrlShift()
					) {
				ThreadUtil.run(new P0() {public void e() {
					ThreadUtil.sleep(200);
					DesktopUI4.combo(new int[] {KeyEvent.VK_CONTROL}, KeyEvent.VK_F5);
					DesktopUI4.type("RU");
					DesktopUI4.type(KeyEvent.VK_ENTER);
					Fs.repeat(3, DesktopUI4.typeF(KeyEvent.VK_DOWN)).e();
					DesktopUI4.type(KeyEvent.VK_RIGHT);
				}});
			}
		}});
		KeyboardHandler.mapReleased('T', new P0() {public void e() {
			if (
					isCtrlShift()
					) {
				ThreadUtil.run(new P0() {public void e() {
					ThreadUtil.sleep(200);
					DesktopUI4.combo(new int[] {KeyEvent.VK_CONTROL}, KeyEvent.VK_F5);
					DesktopUI4.type("RU");
					DesktopUI4.type(KeyEvent.VK_ENTER);
					DesktopUI4.type("EX");
					DesktopUI4.type(KeyEvent.VK_RIGHT);
				}});
			}
		}});

//		KeyboardHandler.mapReleased('V', new P0() {public void e() {
//			if (
//					isCtrlShift()
//					) {
//				ThreadUtil.runStrong(new P0() {public void e() {
//					ThreadUtil.sleep(200);
//					final String old = Clipboard.getText();
//					String newText = Clipboard.copy();
//					System.out.println("Old=" + old);
//					System.out.println("newText=" + newText);
//					ThreadUtil.runStrong(new P0() {public void e() {
//						ThreadUtil.sleep(1000);
//						Clipboard.type(old);
//					}});
//				}});
//			}
//		}});
	}
	
	private static boolean isCtrlShift() {
		return KeyboardHandler.isCtrlPressed() &&
		KeyboardHandler.isShiftPressed() &&
		!KeyboardHandler.isAltPressed();
	}

	public static class Build {
		public static void main(String[] args) {
			System.out.println(BuildUtil.runCommand(QuickMac.class));
		}
	}
}
